<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>配送区域列表</title>
</head>
<body>

<div class="container">

        <div class="comm_crub">
            <span class="now_crub">配送区域列表</span>
            <button type="button" class="btn btn-primary" style="float: right;margin:6px 15px 0px 0px;" onclick="history.go(-1)">返回上一级</button>
        </div>

        <div class="comm_content">

            <table id="flex" style="display:none"></table>

        </div>


</div>

<div id="pop" style="display: none;">
    <div style="width:100%;">

        <div class="container">

            <div class="comm_content">

                <div class="commAttr">
                    <form id="addForm" class="form-horizontal" name="addForm" onsubmit="return false;">

                        <div class="form-group">
                            <label for="send_region_name" class="col-sm-3 control-label"><span class="red">*</span> 配送区域名称：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control w300" id="send_region_name" name="send_region_name" placeholder="请输入配送区域名称" value="" >
                            </div>
                            <input type="hidden" id="send_region_id" name="send_region_id" value="">
                            <input type="hidden" id="sendTypeID" name="sendTypeID" value="<!--{$sendTypeID}-->">
                        </div>
                        <div class="form-group">
                            <label for="areaID" class="col-sm-3 control-label"><span class="red">*</span> 地图区域名称：</label>
                            <div class="col-sm-9">
                                <select class="form-control fl" style="width: 200px;" name="areaID" id="areaID" >
                                    <option value="" selected>请选择</option>
                                    <!--{foreach from=$area_data item=area}-->
                                    <option value="<!--{$area['areaID']}-->"><!--{$area['areaName']}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </div>
                            <input type="hidden" id="areaName" name="areaName" value="">
                        </div>
                        <div class="form-group">
                            <label for="ykg" class="col-sm-3 control-label"><span class="red">*</span> 首重：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control w300" id="ykg" name="ykg" placeholder="请输入首次重量"  value="" >
                            </div>
                            <div>
                                <label class="col-sm-2 control-label">KG</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="freight" class="col-sm-3 control-label"><span class="red">*</span> 实际运费：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control w300" id="freight" name="freight" placeholder="请输入实际运费" value="" >
                            </div>
                            <div>
                                <label class="col-sm-2 control-label">元</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="overweight_freight" class="col-sm-3 control-label"> 理论运费：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control w300" id="overweight_freight" name="overweight_freight" placeholder="请输入理论运费" value="0.00" >
                            </div>
                            <div>
                                <label class="col-sm-2 control-label">元/KG</label>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    var sendTypeID = <!--{$sendTypeID}-->;

    var area = {

        goback: function() {
            self.location = "/quanliadmin/app/system/sendType.pscript?operFlg=1";
        },

        add: function( id ) {
            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"pop",   		 //获取id为"pop"元素内的HTML
                title: id == null ? "正在操作：新增配送区域" : "正在操作：修改配送区域",       //弹出层标题
            //    title: "正在操作：新增配送区域",
                css: "width:800px;",     //设置弹出层样式
                btnName: "保存",         //执行“确定”操作的按钮名称
                btnCall:"area.check();"  //点击确定后执行的方法
            });

            if(id != null){
                $.ajax({
                    type: "POST",
                    url: "/invokingAjax-backend/system/sendType.ajax?operFlg=6&send_region_id="+id,
                    dataType: "JSON",
                    success: function(o) {
                        if(o.code == 200){
                            $('#send_region_id').val(o.data.send_region_id);
                            $('#send_region_name').val(o.data.send_region_name);
                            $("#areaID").val(o.data.areaID);
                            $('#ykg').val(o.data.ykg);
                            $("#freight").val(o.data.freight);
                            $("#overweight_freight").val(o.data.overweight_freight);
                        }else{
                            E.alert(o.message);
                        }
                    }
                });
            }

        },

        //验证配送区域信息
        check:function(){

            dt: "",

            $('#areaName').val($("#areaID").find("option:selected").text());
            this.dt = E.getFormValues("addForm");
            var send_region_name = $.trim( $("#send_region_name").val() );
            var areaID  = $("#areaID").val();
            var ykg = $.trim( $("#ykg").val() );
            var freight  = $.trim( $("#freight").val() );
            var err_msg = '';

            if(send_region_name == ''){
                err_msg += '区域配送名称不能为空，请填写<br />';
            }
            if(areaID == ""){
                err_msg += '地图区域名称不能为空，请填写<br />';
            }
            if(ykg == ""){
                err_msg += '首重不能为空，请填写<br />';
            }
            if(!E.isEmpty(ykg) && !E.isNum(ykg)){
                err_msg += '首重必须是大于0的整数<br />';
            }
            if(freight == ""){
                err_msg += '首重运费不能为空，请填写<br />';
            }
            if(!E.isEmpty(freight) && !E.isNum(freight)){
                err_msg += '首重运费必须是大于等于0的金额<br />';
            }

            if(err_msg != ''){
                E.alert(err_msg);
            }else{
                area.sendAreaEdit();
            }
        },

        sendAreaEdit:function(){
            E.popup.close();
            E.loadding.open("正在保存，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/system/sendType.ajax?operFlg=101&act=edit",
                data: this.dt,
                call: "area.result"
            });
        },

        result:function(o){
            if (o.code == 200) {
                E.alert(o.message, 2, "area.load");
            } else {
                E.alert(o.message);
            }
            E.loadding.close();
        },

        load: function() {
            $("#flex").flexReload();
        },


        del: {

            delete_str: "",

            check: function( o ) {

                this.delete_str = "";
                $.each($("#flex").find("tr"), function(k, v) {
                    if ($(v).hasClass("trSelected")) {
                        area.del.delete_str += "_" + $(v).attr("id").replace("row", "");
                    }
                });
                if (this.delete_str == "")
                    E.alert("请选择要删除的配送区域");
                else {
                    this.delete_str = this.delete_str.substring(1);
                    E.confirm("您确认要删除选中的配送区域吗？", "area.del.execute");
                }

            },

            execute: function() {

                E.loadding.open("正在删除配送区域，请稍候...");
                E.ajax_get({
                    url: "/invokingAjax-backend/system/sendType.ajax?operFlg=101&act=del",
                    data: {
                        str: this.delete_str
                    },
                    call: "area.del.result"
                });

            },

            result: function( o ) {

                E.loadding.close();

                if (o.code == 200) {

                    E.alert(o.message, 2, "area.load");

                } else {
                    E.alert(o.message);
                }

            }

        }

    };

    $("#flex").flexigrid({

        url:"/invokingAjax-backend/system/sendType.ajax?operFlg=5&sendTypeID="+sendTypeID,
        dataType: "json",
        colModel : [
            {display: "操作", width : 100, align: 'center'},
            {display: "配送区域ID", name : "send_region_id" , width : 100, sortable : true},
            {display: "配送区域名称", width : 200},
            {display: "地图区域名称", width : 200},
            {display: "实际运费", width : 140},
            {display: "首重重量（KG）", width : 140},
            {display: "理论运费", width : 140}
        ],
        buttons : [
            {name: "添加", bclass: "add", onpress : "area.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "area.del.check"},
            {separator: true},
            {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
            {separator: true},
            {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
        ],
        sortname: "send_region_id",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        height:200
    });

</script>

</body>
</html>